package com.wuyb.config.security;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * 自定义验证规则
 *
 * @Author: wyb
 * @Date: 2024/01/08/17:39
 * @Description:
 */
@Component
public class SGExpressionRoot {
    public boolean hasAuthority(String auth) {
        Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities();
        for (GrantedAuthority authority : authorities) {
            if (authority.getAuthority().equals(auth)) {
                return true;
            }
        }
        return false;
    }
}
